package com.mofeng.myshop.domain.dto.base;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.mofeng.myshop.domain.po.base.BaseEntity;
import com.mofeng.myshop.until.MyUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;

import java.io.Serializable;
import java.util.Date;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class BaseDto implements Serializable {
    @Schema(description = "id")
    protected String id;

    @Schema(description = "名称")
    protected String name;

    @Schema(description = "备注")
    protected String remarks;

    @Schema(description = "描述")
    protected String description;

    @Schema(description = "排序索引")
    protected Integer orderIndex;

    @Schema(description = "创建时间")
    @TableField(fill = FieldFill.INSERT)
    protected Date createTime;

    @Schema(description = "更新时间")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    protected Date updateTime;

    protected  <T extends BaseEntity> void toBaseEntity(T baseEntity) {
        baseEntity.setId(MyUtil.StringUtil.isEmpty(this.id) ? null : Long.valueOf(this.id));
        if (this.name != null) {
            baseEntity.setName(this.name);
        }
        if (this.remarks != null) {
            baseEntity.setRemarks(this.remarks);
        }
        if (this.description != null) {
            baseEntity.setDescription(this.description);
        }
        if (this.orderIndex != null) {
            baseEntity.setOrderIndex(this.orderIndex);
        }
        if (this.createTime != null) {
            baseEntity.setCreateTime(this.createTime);
        }
        if (this.updateTime != null) {
            baseEntity.setUpdateTime(this.updateTime);
        }
    }
}
